const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
console.log('__dirname-->', path.resolve(__dirname, '..'))
const pathResolve = path.resolve(__dirname, '..')
const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
  entry: {
    app: './src/index.js'
  },
  output: {
    filename: 'js/[name].[chunkhash:8].bundle.js',
    path: path.resolve(__dirname, '../dist')
  },
  plugins: [
    new VueLoaderPlugin(),
    // new CleanWebpackPlugin(['./dist'], {
    //   root: path.resolve(__dirname, '..')
    // }),
    new HtmlWebpackPlugin({
      title: 'MYdemo', //不知道为什么失效了
      template: './index.html',
      hash: true
    }),
    new CopyWebpackPlugin([
      {
        from: './src/assets/',
        to: 'assets'
      }
    ])
  ],
  stats: {
    children: false
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {}
          // other vue-loader options go here
        }
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.less/,
        loaders: ['style-loader', 'css-loader', 'less-loader']
      },

      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        options: {
          name: '[name].[ext]?[hash]'
        }
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        use: ['file-loader']
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      }
    ]
  },
  resolve: {
    alias: {
      vue$: 'vue/dist/vue.esm.js',
	  '@': path.resolve(__dirname,'./../src')
    }
  },
  devServer: {
    // 指定进入 src
    // contentBase: path.join(__dirname, './src'),
    // 自动打开浏览器
    open: true,
    // 指定端口号
    host:'0.0.0.0',
    port: 3002,
	proxy: {
      '/myapi': { 
        // 请求的 : https://douban.uieee.com/v2/movie/in_theaters
        target: 'http://api.fcw-china.com',
        // target: 'https://house.fcw-china.com',
        // target: 'http://fcapp.fcw-china.com',
        pathRewrite: { '^/myapi': '' },
        // 设置https
        // secure: true,
        // 必须设置该项
        changeOrigin: true
      }
    },
  }
}

// "start": "webpack --watch --config config/webpack.dev.js --mode development --env.NODE_ENV=development --progress",
